package com.googlecode.loframework.controller
{
	import com.googlecode.loframework.data.PersonalityQuestionVO;
	import com.googlecode.loframework.model.QuizProxy;
	import com.googlecode.loframework.view.components.quizzes.IChoice;
	
	import flash.utils.Dictionary;
	
	import mx.core.UIComponent;
	
	import org.puremvc.as3.interfaces.INotification;
	import org.puremvc.as3.interfaces.IProxy;
	import org.puremvc.as3.patterns.command.SimpleCommand;

	/**
	 * Triggered by user action. Whenever the user changes a choice, within a personality question
	 * the new value of the selected item is added to PeronalityQuestionVO.
	 *  
	 * @author USER
	 * 
	 */
	public class PersonalityQuestionChangeCommand extends SimpleCommand
	{
		override public function execute(notification:INotification):void
		{
			// get the choice selected by the user
			var choice:IChoice = notification.getBody() as IChoice;
			
			// obtain its value
			var value:* = choice.value;

			// get the quiz proxy
			var proxy:IProxy = facade.retrieveProxy(QuizProxy.NAME);
			
			// get the dictionary used to hold references to choices and their associated VOs
			var choices:Dictionary = (proxy as QuizProxy).questionList as Dictionary;
			
			// get the VO corresponding to the choice selected
			var vo:PersonalityQuestionVO = choices[(choice as UIComponent).parent] as PersonalityQuestionVO;
	
			// change the value
			if(vo != null)
			{
				vo.value = value;
			}
			
				
		}
		
	}
}